//get(data,'a[3].b')
// const obj = {a:{b:{c:["hello world"]}}}
//obj?.a?.b?.c
//_.get(obj,"a.b.c",null)
//_.get(obj,"a['b']['c']",null)
const obj = { a: { _bbbb: { c: ["hello world"] } } };
const get = (data, path, defaultValue = void 0) => {
  //差异化抹平
  const paths = path.replace(/\[["|'](\w+)["|']\]/g, ".$1").split(".");
  console.log(paths);
  return (
    paths.reduce((prev, cur) => {
      console.log(prev, cur);
      if (prev === undefined) return undefined;
      if (cur in prev) {
        return prev[cur];
      } else {
        return undefined;
      }
    }, data) || defaultValue
  );
};
console.log(get(obj, "a._bbbb.c", null));
console.log(get(obj, "a['b']['c']", null));
